package com.ssfeng.youxia.controller;

import com.ssfeng.youxia.schedule.YouxiaScheduler;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
 * Created by liyuhang on 2019-09-16.
 * 用于手动触发定时任务
 */
@Controller
@RequestMapping(value = "/schedule")
public class ScheduleController {

    private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);

    @Autowired
    private MappingJackson2JsonView mappingJackson2JsonView;


    @Autowired
    private YouxiaScheduler youxiaScheduler;

    @RequestMapping("/scheduleTimeTask")
    public ModelAndView scheduleTimeTask(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView(mappingJackson2JsonView);
        modelAndView.addObject("code", "ok");
        try {
            youxiaScheduler.scheduleTimeTask();
        } catch (SchedulerException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return modelAndView;
    }
}
